package router

import (
	restfulspec "github.com/emicklei/go-restful-openapi/v2"
	"github.com/emicklei/go-restful/v3"
	"webGoDemo/controllers"
	"webGoDemo/model"
	"webGoDemo/presenter"
)

func AddOperateRouter(container *restful.Container) {
	ws := new(restful.WebService)
	ws.
		Path("/operate/").
		Consumes(restful.MIME_XML, restful.MIME_JSON).
		Produces(restful.MIME_JSON, restful.MIME_XML) // you can specify this presenter route as well
	tags := []string{"operate"}
	// 状态检查
	ws.Route(ws.GET("/checkState").To(controllers.GetState).
		// docs
		Doc("operate-checkState").
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Param(checkStateParam(ws, "instanceId")).
		Param(checkStateParam(ws, "tenantId")).
		Writes(0).
		Returns(200, "集群更新或部署成功", struct {
			presenter.CommonRes
		}{}).
		Returns(400, "参数错误", nil).
		Returns(500, "内部错误", nil))
	// notify
	ws.Route(ws.GET("/notify").To(controllers.Notify).
		// docs
		Doc("operate-notify").
		Metadata(restfulspec.KeyOpenAPITags, tags).
		Reads(model.NotifyRequestFromUI{}).
		Writes(presenter.JsonRes{Data: model.NotifyRequestToOP{}}).
		Returns(200, "集群更新或部署成功", struct {
			presenter.CommonRes
			Data model.NotifyRequestToOP `json:"data"`
		}{}).
		Returns(400, "参数错误", nil).
		Returns(500, "内部错误", nil))
	container.Add(ws)
}
